package routes

import (
	"github.com/gin-gonic/gin"
	"html/template"
	"io/fs"
	"net/http"
)

// LoadHTML 注册模版
func LoadHTML(router *gin.Engine, tplFiles fs.FS) {

	// embed 导入所有模板
	temp := template.New("")
	temp = template.Must(temp.ParseFS(tplFiles, "**/*"))

	// 导入所有模板
	//router.LoadHTMLGlob("website/tpl/**/*")
	//temp := template.Must(template.New("").ParseGlob("website/tpl/**/*"))
	router.SetHTMLTemplate(temp)
	for _, v := range temp.Templates() {
		tplName := v.Name()
		router.GET(tplName, func(c *gin.Context) {
			c.HTML(http.StatusOK, tplName, nil)
		})
	}

}
